home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / utility / utilwb / wbstars2.lha / WBStars2.0 / source / WBStars_plot.c < prev    next >
C/C++ Source or Header  |  1996-12-18  |  3KB  |  161 lines

  1. /* $VER: WBStars_plot.c 2.0 (18 Dec 1996)
  2. */
  3.  
  4. #include <exec/types.h>
  5. #include <exec/memory.h>
  6. #include <intuition/intuition.h>
  7. #include <proto/exec.h>
  8. #include <clib/alib_protos.h>
  9.  
  10. #include "WBStars_plot.h"
  11.  
  12. struct Flake
  13. {
  14.     struct Flake    *next;
  15.     struct Flake    *last;
  16.     int    x;
  17.     int    y;
  18.     int    sticky;
  19.     char    drawn;
  20.     int    dir;
  21. };
  22.  
  23. void    NewFlake( void );
  24. void    ClearFlake(struct Flake *f);
  25.  
  26. struct Flake    *Flakes        = NULL;
  27. int         Flake_cnt    = 0;
  28.  
  29. void    InitObjects()
  30. {
  31.     /* nothing to do here */
  32. }
  33.  
  34. void    NewFlake()
  35. {
  36.     struct Flake    *f;
  37.  
  38.     if( ((Max_Objects<0)||(Flake_cnt<Max_Objects)) && (f=(struct Flake*)AllocMem(sizeof(struct Flake),0)) )
  39.     {
  40.         f->next        = Flakes;
  41.         if( Flakes!=NULL ) Flakes->last    = f;
  42.         f->last        = NULL;
  43.         f->x        = RangeRand(width);
  44.         f->y        = 0;
  45.         f->sticky    = 0;
  46.         f->drawn    = FALSE;
  47.         Flakes        = f;
  48.         Flake_cnt++;
  49.     }
  50. }
  51.  
  52. void    ClearFlake(struct Flake *f)
  53. {
  54.     if( f->next!=NULL ) f->next->last=f->last;
  55.     if( f->last!=NULL )
  56.     {
  57.         f->last->next=f->next;
  58.     }
  59.     else
  60.     {
  61.         Flakes=f->next;
  62.     }
  63.     FreeMem( f, sizeof(struct Flake) );
  64.     Flake_cnt--;
  65. }
  66.  
  67. void    ClearObjects()
  68. {
  69.     struct    Flake    *f;
  70.     char    dummy;
  71.  
  72.     while( Flakes!=NULL )
  73.     {
  74.         dummy = ClearPixelTest(Flakes->x,Flakes->y);
  75.  
  76.         f=Flakes->next;
  77.         FreeMem( Flakes, sizeof(struct Flake) );
  78.         Flakes=f;
  79.     }
  80.     Flake_cnt=0;
  81. }
  82.  
  83. void    PlotObjects()
  84. {
  85.     struct Flake    *f;
  86.     struct Flake    *next;
  87.     int        newx;
  88.     int        newy;
  89.     int        addx;
  90.     char    dummy;
  91.  
  92.     NewFlake();
  93.  
  94.     for(f=Flakes; f!=NULL; f=next)
  95.     {
  96.         next        = f->next;
  97.         if( (!f->sticky) || (Max_Stick>=0) )
  98.         {
  99.             newy        = f->y +1;
  100.  
  101.             if( f->dir==0 )
  102.             {
  103.                 addx    = RangeRand(3) -1;
  104.             }
  105.             else
  106.             {
  107.                 addx    = RangeRand(2)*SIGN(f->dir);
  108.             }
  109.             newx        = f->x +addx;
  110.  
  111.             LockPlotArea();
  112.  
  113.             if( (newy>=height) || (newx<0) || (newx>=width) )
  114.             {
  115.                 if(f->drawn) dummy=ClearPixelTest(f->x,f->y);
  116.                 ClearFlake(f);
  117.             }
  118.             else
  119.             {
  120.                 if( (!f->drawn) || Test1Pixel(f->x,f->y) )
  121.                 {
  122.                     if( SetPixelTest(newx,newy) )
  123.                     {
  124.                         if(f->drawn) ClearPixel(f->x,f->y);
  125.                         f->x        = newx;
  126.                         f->y        = newy;
  127.                         f->drawn    = TRUE;
  128.                         f->sticky    = 0;
  129.                         f->dir        = addx;
  130.                     }
  131.                     else
  132.                     {
  133.                         if( SetPixelTest(f->x,newy) )
  134.                         {
  135.                             if(f->drawn) ClearPixel(f->x,f->y);
  136.                             f->y        = newy;
  137.                             f->drawn    = TRUE;
  138.                             f->sticky    = 0;
  139.                             f->dir        = 0;
  140.                         }
  141.                         else
  142.                         {
  143.                             if( ((f->sticky++)>Max_Stick) && (Max_Stick>=0) )
  144.                             {
  145.                                 dummy=ClearPixelTest(f->x,f->y);
  146.                                 ClearFlake(f);
  147.                             }                        
  148.                         }
  149.                     }
  150.                 }
  151.                 else
  152.                 {
  153.                     dummy=ClearPixelTest(f->x,f->y);
  154.                     ClearFlake(f);
  155.                 }
  156.             }
  157.         }
  158.         UnlockPlotArea();
  159.     }
  160. }
  161.